<?php

class ConfigAction extends CommonAction {

    /**
     * 进入编辑
     * */
	public function edit(){
	   
        $where['mate_key'] = C('PROJECT_NAME_CN');
        $config1 = M('Config')->where($where)->find();
        
        $where = array();
        $where['mate_key'] = C('PROJECT_NAME_EN');
        $config2 = M('Config')->where($where)->find();
        
        $where = array();
        $where['mate_key'] = C('PROJECT_BBS_URL');
        $config3 = M('Config')->where($where)->find();
        
		$this->assign(C('PROJECT_NAME_CN') , $config1['mate_value']);
        $this->assign(C('PROJECT_NAME_EN') , $config2['mate_value']);
        $this->assign(C('PROJECT_BBS_URL') , $config3['mate_value']);
		$this->display();
	}
    
    /**
     * 更新项目名称
     * */
	public function update(){
		$project_name_cn = $_REQUEST[C('PROJECT_NAME_CN')];
        $project_name_en = $_REQUEST[C('PROJECT_NAME_EN')];
        $project_bbs_url = $_REQUEST[C('PROJECT_BBS_URL')];
        if(isset($project_name_cn)){
            //更新项目名称
            $data['mate_value'] = $project_name_cn;
            $where['mate_key'] = C('PROJECT_NAME_CN');
            M('Config')->where($where)->save($data);
            
            //更新英文目录名称
            $data['mate_value'] = $project_name_en;
            $where['mate_key'] = C('PROJECT_NAME_EN');
            M('Config')->where($where)->save($data);
            
            //更新BBS链接
            $data['mate_value'] = $project_bbs_url;
            $where['mate_key'] = C('PROJECT_BBS_URL');
            M('Config')->where($where)->save($data);
            
            $this->successAjax("操作成功");
		}else{
            $this->errorAjax("请输入项目名称");
		}
	}
	
}